<?php
	@$hot_line         = $_POST['hot-line'];
	@$email            = $_POST['email'];
	@$yahoo            = $_POST['yahoo'];
	@$skype            = $_POST['skype'];
	@$footer_vi        = $_POST['footer_vi'];
	@$footer_en        = $_POST['footer_en'];
	@$intro_contact_vi = $_POST['intro_contact_vi'];
	@$intro_contact_en = $_POST['intro_contact_en'];
	
	$show_msg = false;
	$msg = '';
	if(isset($hot_line) && isset($email) && isset($yahoo) && isset($skype))
	{
		$esc_arr = $exec_mysql->escape_string(array($hot_line, $email, $yahoo, $skype, $footer_vi, $footer_en));
		$r1 = $exec_mysql->execute("update extra set val_vi = '$esc_arr[0]', val_en = '$esc_arr[0]'  where ref = 'hot_line'", 0);
		$r2 = $exec_mysql->execute("update extra set val_vi = '$esc_arr[1]', val_en = '$esc_arr[1]' where ref = 'email'", 0);
		$r3 = $exec_mysql->execute("update extra set val_vi = '$esc_arr[2]', val_en = '$esc_arr[2]' where ref = 'yahoo'", 0);
		$r4 = $exec_mysql->execute("update extra set val_vi = '$esc_arr[3]', val_en = '$esc_arr[3]' where ref = 'skype'", 0);
		$r5 = $exec_mysql->execute("update extra set val_vi = '$esc_arr[4]', val_en = '$esc_arr[5]'  where ref = 'footer'", 0);
		$r6 = $exec_mysql->execute("update node set content_vi = '$intro_contact_vi', content_en = '$intro_contact_en' where id_type = 6", 0);
		//echo $intro_contact;
		
		$show_msg = true;
		if($r1 && $r2 && $r3 && $r4 && $r5){
			$msg = 'Cập nhật thông tin doanh nghiệp thành công';
		}
		else{
			$msg = 'Đã có lỗi xãy ra khi lưu thông tin, vui lòng thử lại sau';
		}
	}
	
	$hl = $exec_mysql->execute("select val_vi from extra where ref = 'hot_line'", 1);
	$em = $exec_mysql->execute("select val_vi from extra where ref = 'email'", 1);
	$yh = $exec_mysql->execute("select val_vi from extra where ref = 'yahoo'", 1);
	$sk = $exec_mysql->execute("select val_vi from extra where ref = 'skype'", 1);
	$ft_vi = $exec_mysql->execute("select val_vi from extra where ref = 'footer'", 1);
	$ft_en = $exec_mysql->execute("select val_en from extra where ref = 'footer'", 1);
	$ic_vi = $exec_mysql->execute("select content_vi from node where id_type = 6", 1);
	$ic_en = $exec_mysql->execute("select content_en from node where id_type = 6", 1);
?>
<script type="text/javascript">
	
	var show = '<?php echo $show_msg; ?>';
	
	if(show == true){
		showAlert('Thông báo', '<?php echo $msg; ?>', '');
	}
	
	function checkSubmit(){
		
		if($('#hot-line').val() == ''){
			showAlert('Input required', 'Vui lòng nhập Hot-line', 'hot-line');
			return false;
		}
		if($('#email').val() == ''){
			showAlert('Input required', 'Vui lòng nhập email liên hệ', 'email');
			return false;
		}
		if(!checkEmailAddr($('#email').val())){
			showAlert('Input not availid', 'Địa chỉ email không đúng', 'email');
			return false;
		}
		if($('#yahoo').val() == ''){
			showAlert('Input required', 'Vui lòng nhập hỗ trợ trực tuyến Yahoo', 'yahoo');
			return false;
		}
		if($('#skype').val() == ''){
			showAlert('Input required', 'Vui lòng nhập hỗ trợ trực tuyến Skype', 'skype');
			return false;
		}
	}
</script>
<form method="post" onsubmit="return checkSubmit()">
	<p class="group-line">
        <span class="group-title">Thông tin doanh nghiệp</span>
    </p>
    <table class="form-layout">
    	<tr>
        	<td width="165">Hot-line<span class="mask">*</span></td>
            <td><input type="text" name="hot-line" id="hot-line" size="50" value="<?php echo htmlspecialchars($hl); ?>" /></td>
        </tr>
        <tr>
        	<td>Email<span class="mask">*</span></td>
            <td><input type="text" name="email" id="email" size="50" value="<?php echo htmlspecialchars($em); ?>" /></td>
        </tr>
        <tr>
        	<td>Hỗ trợ trực tuyến Yahoo<span class="mask">*</span></td>
            <td><input type="text" name="yahoo" id="yahoo" size="50" value="<?php echo htmlspecialchars($yh); ?>" /></td>
        </tr>
        <tr>
        	<td>Hỗ trợ trực tuyến Skype<span class="mask">*</span></td>
            <td><input type="text" name="skype" id="skype" size="50" value="<?php echo htmlspecialchars($sk); ?>" /></td>
        </tr>
    </table>
    <p class="group-line">
        <span class="group-title">Footer site</span>
    </p>
    <table class="form-layout">
        <tr>    
            <td width="165" rowspan="2">Thông tin cuối trang<br />(Footer information)</td>
            <td>
                <input type="text" name="footer_vi" size="50" value="<?php echo htmlspecialchars($ft_vi); ?>" />
            </td>
        </tr>
        <tr>
            <!--<td width="165">Footer information</td>-->
            <td>
                <input type="text" name="footer_en" size="50" value="<?php echo htmlspecialchars($ft_en); ?>" />
            </td>
        </tr>
    </table>
    <p class="group-line">
        <span class="group-title">Liên hệ</span>
    </p>
     <table class="form-layout">
    	<tr>
            <td>
            	<textarea id="editor_vi" name="intro_contact_vi"><?php echo $ic_vi; ?></textarea>
                <script>
				CKEDITOR.replace('editor_vi',{
					enterMode: CKEDITOR.ENTER_BR
				});
            </script>
            </td>
        </tr>
        <tr>
            <td>
            	<textarea id="editor_en" name="intro_contact_en"><?php echo $ic_en; ?></textarea>
                <script>
				CKEDITOR.replace('editor_en',{
					enterMode: CKEDITOR.ENTER_BR
				});
            </script>
            </td>
        </tr>
    </table>
    <p class="footer-form">
    	<input type="submit" value="Cập nhật" />
        <input type="reset" value="Undo last edit" />
    </p>
</form>